package org.gnyxy.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.gnyxy.entity.Collect;

import java.util.List;

@Mapper
public interface CollectMapper {
    @Insert("insert into collect (user_id, dish_id,material_id, create_time, deleted) values " +
            "(#{userId},#{dishId},#{materialId},#{createTime},#{deleted})")
    void insert(Collect collect);

    @Update("update collect set deleted = 1 where id = #{id}")
    void delete(Long id);

    @Select("select * from collect where user_id = #{userId} and deleted = 0")
    List<Collect> getAllByUserId(Long userId);


    void deleteByDishIds(List<Long> dishIds, Long userId);

    void deleteByMaterialIds(List<Long> materialIds, Long userId);

    @Select("select count(*) from collect where dish_id = #{dishId} and user_id = #{userId} and deleted = 0")
    Long selectDishNumBydishId(Long dishId,Long userId);

    @Select("select count(*) from collect where material_id = #{materialId} and user_id = #{userId} and deleted = 0")
    Long selectMaterialNumByMaterialId(Long materialId, Long userId);
}
